from lib.w.glade import *

from relatorio.base import *

class Input(GladeWidget):

	def __init__(self, ws):
		self.ws = ws
		self.db = ws.db

		self.initialize("relatorio/glade/cliente.glade", "cliente")
		self.configure()
		gtk.main()

	def configure(self):

		sql = "select grid, nome from cliente order by nome"
		rs = self.db.get_list_result(sql)
		cliente_list = [(None, 'Todos os clientes')] + rs
		self.w.cliente.set_items(cliente_list)
		self.w.cliente.set_active(0)

	def on_bt_visualizar_clicked(self, *args):

		rel = Relatorio(self.ws, self.get_dict(), 'cliente.rel')
		rel.preview()

	def quit(self, *args):

		self.w._top.destroy()
		gtk.main_quit()

if __name__ == '__main__':
	from lib.workspace import *
	d = {'dbname': 'germano', 'host': 'localhost', 'user': 'postgres'}
	ws = workspace()
	ws.connect_db(d)
	Input(ws)
